package volkov.ja.pages;

import static org.openqa.selenium.support.ui.ExpectedConditions.*;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.Select;

public class MovieEditPage extends InternalPage {

	public MovieEditPage(PageManager pages) {
		super(pages);
	}
	
	@FindBy(name = "imdbid")
	private WebElement IMDbField;

	@FindBy(name = "name")
	private WebElement titleField;

	@FindBy(name = "year")
	private WebElement yearField;

	@FindBy(name = "notes")
	private WebElement notesField;
	
	@FindBy(name = "submit")
	private WebElement submitButton;

	public String getTitle() {
		return titleField.getAttribute("value");
	}

	public String getIMDb() {
		return IMDbField.getAttribute("value");
	}
	
	public String getYear() {
		return yearField.getAttribute("value");
	}
	
	public String getNotes() {
		return notesField.getAttribute("value");
	}

	public MovieEditPage setTitle(String text) {
		titleField.sendKeys(text);
		return this;
	}

	public MovieEditPage setIMDb(String text) {
		IMDbField.sendKeys(text);
		return this;
	}

	public MovieEditPage setYear(String text) {
		yearField.sendKeys(text);
		return this;
	}
	
	public MovieEditPage setNotes(String text) {
		notesField.sendKeys(text);
		return this;
	}
	
	public void clickSaveButton() {
		submitButton.click();
	}

	public MovieEditPage ensurePageLoaded() {
		super.ensurePageLoaded();
		pages.getWait().until(presenceOfElementLocated(By
				.cssSelector("form#updateform")));
		return this;
	}
	
	@Override
	public String getPageRelativeUrl() {
		return "?go=add";
	}
	
}
